/*
 * @Author: zhs
 * @Date: 2024-01-03 13:11:53
 * @LastEditTime: 2024-01-03 15:26:26
 * @LastEditors: your name
 * @Description: 
 * @FilePath: \vue-project\src\stores\counter.ts
 */
import { ref, computed } from 'vue'
// import { defineStore } from 'pinia'

// export const useCounterStore = defineStore('counter', () => {
//   const count = ref(0)
//   const doubleCount = computed(() => count.value * 2)
//   function increment() {
//     count.value++
//   }

//   return { count, doubleCount, increment }
// }) 
import { defineStore } from 'pinia'
export const useAgeStore = defineStore('dingding', {
  state: () => {
    return {
      age: 0,
      name: "刘禹锡",
      arr: [1, 2, 3, 4],
    }
  },
  getters: {
    // gettersAge(state) {
    //   return state.age + 5
    // }

    gettersAge(state) {
      const useStore = useCounterStore()
      return state.age + useStore.counter
    }

  },
  actions: {
    addAge() {
      this.age++
    }
  },
  // 开启数据缓存
  persist: {
    enabled: true
  }

})

export const useCounterStore = defineStore('main', () => {
  const counter = ref(30);
  const gettersCounter = computed(() => {
    return counter.value + 5;
  })
  function addCounter(val: any) {
    counter.value = counter.value + val;
    console.log(val);
  }

  return { counter, gettersCounter, addCounter }

})
